
<%
	// Get form data.
	String scholarship_id = request.getParameter("scholarship_id");
	String application_id = request.getParameter("application_id");
	String rating = request.getParameter("rating");

	java.sql.Connection conn = null;
	try {
		// Check if rating is an integer from 0 - 5.
		int ratingNum = Integer.parseInt(rating);
		if (ratingNum < 0 || ratingNum > 5) {
			throw new Exception();
		}

		// Get SQL information.
		String myJDBCDriver = (String) session.getAttribute("myJDBCDriver");
		String myURL = (String) session.getAttribute("myURL");
		String myUserID = (String) session.getAttribute("myUserID");
		String myPassword = (String) session.getAttribute("myPassword");

		// Connect to the database.
		Class.forName(myJDBCDriver).newInstance();
		java.util.Properties sysprops = System.getProperties();
		sysprops.put("user", myUserID);
		sysprops.put("password", myPassword);
		conn = java.sql.DriverManager.getConnection(myURL, sysprops);

		java.sql.Statement statement = conn.createStatement();
		statement.executeUpdate("UPDATE applications SET rating='" + rating + "' WHERE id='" + application_id + "'");
		session.setAttribute("errors", "* The rating has sucessfully been entered.");
		response.sendRedirect("review.jsp?scholarship_id=" + scholarship_id);
	} catch (Exception e) {
		// The rating could not be parsed into an integer.
		session.setAttribute("errors", "* You entered " + rating + ". Rating must be an integer from 0 to 5.");
		response.sendRedirect("review.jsp?scholarship_id=" + scholarship_id);
	} finally {
		try {
			conn.close();
		} catch (Exception ee) {
		}
	}
%>